using XnaInput = Microsoft.Xna.Framework.Input;

using Storyteller.Framework.Math;

namespace Storyteller.Framework.Input
{
	public class GamePad
	{
		public enum Button
		{
			None = 0,

			A = 4096, B = 8192, X = 16384, Y = 32768,

			RB = 512, LB = 256,

			Start = 16, Back = 32,

			LeftStick = 64, RightStick = 128,

			Up = 1, Down = 2, Left = 4, Right = 8,
		}

		public enum Trigger
		{
			Left, Right
		}

		public enum ThumbStick
		{
			Left, Right
		}

		public static bool IsConnected(int gamepadIndex)
		{
			return Game.Instance.GamePadStates[gamepadIndex].IsConnected;
		}

		public static bool IsButtonDown(int gamepadIndex, Button button)
		{
			return Game.Instance.GamePadStates[gamepadIndex].IsButtonDown((XnaInput.Buttons)button);
		}

		public static Vector2 GetThumbStickValue(int gamepadIndex, ThumbStick thumbStick)
		{
			if (thumbStick == ThumbStick.Left)
				return new Vector2(Game.Instance.GamePadStates[gamepadIndex].ThumbSticks.Left.X,
					Game.Instance.GamePadStates[gamepadIndex].ThumbSticks.Left.Y);
			return new Vector2(Game.Instance.GamePadStates[gamepadIndex].ThumbSticks.Right.X,
				Game.Instance.GamePadStates[gamepadIndex].ThumbSticks.Right.Y);
		}

		public static float GetTriggerValue(int gamepadIndex, Trigger trigger)
		{
			if (trigger == Trigger.Left)
				return Game.Instance.GamePadStates[gamepadIndex].Triggers.Left;
			return Game.Instance.GamePadStates[gamepadIndex].Triggers.Right;
		}
	}
}
